package com.puboot.common.config;

import com.puboot.common.config.properties.FileUploadProperties;
import net.anumbrella.seaweedfs.core.FileSource;
import net.anumbrella.seaweedfs.core.FileTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * @author Mr.Lang
 */
@Configuration
public class SeaweedConfig {

    @Autowired
    private FileUploadProperties fileUploadProperties;

    @Bean
    public FileTemplate fileTemplate() {
        FileSource fileSource = new FileSource();
        fileSource.setHost(fileUploadProperties.getSeaweedMasterHost());
        fileSource.setPort(fileUploadProperties.getSeaweedMasterPort());
        try {
            fileSource.startup();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new FileTemplate(fileSource.getConnection());
    }
}
